import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *
testCase="DBshop011_商品管理管理商品添加商品"
# 打开网页，登录后台
firefox=openBrowser("http://localhost/dbshop/admin")
DBshopLoginAdmin(firefox)
# 点击商品管理管理商品。
DBshopEnterMenu2(firefox,"商品管理","管理商品")
# 点击添加商品按钮
firefox.find_element_by_partial_link_text("添加商品").click()
# 商品名称填写“苹果XR”
firefox.find_element_by_id("goods_name").send_keys(goodsName)
# 本店价格“7999”
firefox.find_element_by_id("goods_shop_price").send_keys(goodsPrice)
# 商品类型“虚拟商品”
firefox.find_element_by_xpath("//option[text()='虚拟商品']").click()
# 点击商品分类,选择商品类型"智能设备"
firefox.find_element_by_link_text("商品分类").click()
firefox.find_element_by_id("class_id_17").click()
# 点击“保存商品”按钮
firefox.find_element_by_xpath("//button[contains(text(),' 保存商品')]").click()
time.sleep(2)
# 断言，查看添加的商品是否存在
try:
    if firefox.find_element_by_xpath("//td[contains(.,%s)]"%goodsName).is_displayed():
        writeLog("%s 测试通过"%testCase)
except:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
firefox.quit()